﻿using System;
using System.Windows.Input;
using ResxHelper.Object;

namespace ResxHelper.Logic.Actions
{
    public class SaveActionInvoker
    {
        public static void Save(object input, SaveFileType saveType, string filePath)
        {
            ICommand saveAction = null;
            switch (saveType)
            {
                case SaveFileType.CsvString:
                    saveAction = new SaveCsvAction((ResourceFile)input, filePath);
                    break;
                case SaveFileType.Excel:
                    saveAction = new SaveExcelAction((ResourceFile)input, filePath);
                    break;
                case SaveFileType.ResourceFile:
                    saveAction = new SaveResxAction((ResourceFile)input, filePath);
                    break;
                case SaveFileType.AndroidResource:
                    saveAction = new SaveAndroidResourceAction((ResourceFile) input, filePath);
                    break;
                case SaveFileType.Zip:
                    var request = (SaveZipRequest) input;
                    request.SaveDirectory = filePath;
                    saveAction = new SaveZipAction(request);
                    break;
            }

            if (saveAction == null || !saveAction.CanExecute(null))
            {
                throw new ApplicationException("File could not be saved. Verify path is correct and file is not null or default.");
            }

            saveAction.Execute(null);
        }
    }
}
